import { createStore, combineReducers, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
function userReducer(state, action) {
  state = state || {
    name: "珠峰",
    age: 13
  }
  switch (action.type) {
    case 'changeName':
      state.name = action.name
      break;
    case 'changeAge':
      state.age = action.age;
      break
    default:
      break;
  }
  return {
    ...state
  }
}
function colorReducer(state, action) {
  state = state || {
    color: 'red'
  }
  if (action.type == 'changeColor') {
    state.color = action.color
  }
  return {
    ...state
  }
}
let rootReducer = combineReducers({
  userInfo: userReducer,
  colorInfo: colorReducer
})
export default createStore(rootReducer, applyMiddleware(thunk))
// {getState,subscribe,dispatch}